import 'package:flutter/material.dart';
import 'package:flutter2/colors.dart';
import 'package:flutter2/ui/home.dart';
import 'package:flutter2/ui/login.dart';
import 'package:flutter2/utils/string.dart';
import 'package:flutter2/utils/system_bar.dart';
import 'package:flutter2/utils/user.dart';
import 'package:get/get.dart';

class SplashPage extends StatefulWidget {
  const SplashPage({super.key});

  @override
  State<SplashPage> createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  @override
  void initState() {
    super.initState();
    () async {
      await Future.delayed(Duration(seconds: 1));
      if (UserUtil.isLogin()) {
        Get.off(() => HomePage());
      } else {
        Get.off(() => LoginPage());
      }
    }();
  }

  @override
  Widget build(BuildContext context) {
    return AnnotatedRegion(
      value: systemUiOverlayStyle,
      child: Scaffold(
        body: Container(
          color: splashBg,
          child: Center(
            child: Image.asset(
              "ic_splash".toImage(),
              width: 112,
              height: 112,
            ),
          ),
        ),
      ),
    );
  }
}
